package wanba.wanbatv.com.wudao.app;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.wifi.WifiManager;

import wanba.wanbatv.com.wudao.util.Util;
import wanba.wanbatv.com.wudao.utils.Product;


/**
 * Created by Forcs on 15/7/22.
 * @author Forcs
 */
public class WbApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        try {
            //从androidmainfest.xml获取产品渠道号
            final PackageManager pm = getPackageManager();
            final String pkgName = getPackageName();
            ApplicationInfo appInfo = pm.getApplicationInfo(pkgName,
                    PackageManager.GET_META_DATA);
            Product.flavor = appInfo.metaData.getString("PRODUCT_FLAVOR");
            Product.appId = appInfo.metaData.getString("PRODUCT_APPID");
            Product.appKey = appInfo.metaData.getString("PRODUCT_APPKEY");
            Product.packageName = pkgName;
            final PackageInfo pi = pm.getPackageInfo(pkgName, 0);
            Product.versionName = pi.versionName;
            Product.versionCode = pi.versionCode;
            Product.stb = Util.getDeviceId(this);
            WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            Product.macAddr = wm.getConnectionInfo().getMacAddress();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
